///时间转换将秒转换为分钟:秒
String hkDurationTransform(int seconds) {
  int m = (seconds / 60).truncate();
  int s = seconds - m * 60;
  if (s < 10) {
    return '$m:0$s';
  }
  return '$m:$s';
}

///数字转万
String hkCountFormat(int count) {
  String views = "";
  if (count > 9999) {
    views = "${(count / 10000).toStringAsFixed(2)}万";
  } else {
    views = count.toString();
  }
  return views;
}

/// 视频时长转换
String hkFormatDuration(Duration position) {
  final ms = position.inMilliseconds;

  int seconds = ms ~/ 1000;
  final int hours = seconds ~/ 3600;
  seconds = seconds % 3600;
  final minutes = seconds ~/ 60;
  seconds = seconds % 60;

  final hoursString = hours >= 10
      ? '$hours'
      : hours == 0
          ? '00'
          : '0$hours';

  final minutesString = minutes >= 10
      ? '$minutes'
      : minutes == 0
          ? '00'
          : '0$minutes';

  final secondsString = seconds >= 10
      ? '$seconds'
      : seconds == 0
          ? '00'
          : '0$seconds';

  final formattedTime =
      '${hoursString == '00' ? '' : '$hoursString:'}$minutesString:$secondsString';

  return formattedTime;
}

/// target  要转换的数字
/// postion 要保留的位数
/// isCrop  true 直接裁剪 false 四舍五入
/// 案例:'${hkFormatNum(proprot, position:2, isCrop: true)}%'
String hkFormatNum(num target,{int position = 2,bool isCrop = false}) {
  String t = target.toString();
  // 如果要保留的长度小于等于0 直接返回当前字符串
  if (position < 0) {
    return t;
  }
  if (t.contains(".")) {
    String t1 = t.split(".").last;
    if (t1.length >= position) {
      if (isCrop) {
        // 直接裁剪
        return t.substring(0, t.length - (t1.length - position));
      } else {
        // 四舍五入
        return target.toStringAsFixed(position);
      }
    } else {
      // 不够位数的补相应个数的0
      String t2 = "";
      for (int i = 0; i < position - t1.length; i++) {
        t2 += "0";
      }
      return t + t2;
    }
  } else {
    // 不含小数的部分补点和相应的0
    String t3 = position > 0 ? "." : "";

    for (int i = 0; i < position; i++) {
      t3 += "0";
    }
    return t + t3;
  }
}